from typing import Any

from sqlalchemy import select, insert, update, delete

from recruit.adapter.database.gateway.resume_base import BaseResumeGateway
from recruit.adapter.database.models import ResumeContact
from recruit.adapter.stubs import StubResumeContact
from recruit.domain.models.resume_id import ResumeId


class ResumeContactGateway(BaseResumeGateway, StubResumeContact):
    async def create(self, **kwargs: Any) -> ResumeContact:
        stmt = insert(ResumeContact).values(**kwargs).returning(ResumeContact)
        return await super().create(stmt)

    async def get_one(self, **kwargs: Any) -> ResumeContact | None:
        stmt = select(ResumeContact).filter_by(**kwargs)
        return await super().get_one(stmt)

    async def check_resume(
            self,
            resume_id: ResumeId,
    ) -> bool:
        stmt = select(ResumeContact).where(
            ResumeContact.resume_id == resume_id
        ).exists()
        return await super().check_resume(stmt)

    async def update(
            self,
            resume_id: ResumeId,
            **kwargs: Any
    ) -> ResumeContact:
        stmt = update(ResumeContact).values(**kwargs).where(
            ResumeContact.resume_id == resume_id
        ).returning(ResumeContact)
        return await super().update(stmt)

    async def delete(self, resume_id: ResumeId) -> None:
        stmt = delete(ResumeContact).where(
            ResumeContact.resume_id == resume_id
        )
        await super().delete(stmt)
